#include "DrawableRasterLayer.h"
#include <QPainter>
#include <TGS/MapControl2.0/RenderContext.h>

DrawableRasterLayer::DrawableRasterLayer(const QString& filePath)
	: RasterLayer(filePath)
{
}


DrawableRasterLayer::~DrawableRasterLayer(void)
{
}

void DrawableRasterLayer::setDrawPolygon( const Polygon& drawedPolygon )
{
	if(!isVisible()) return;

	_drawedPolygons.push_back(drawedPolygon);
}

void DrawableRasterLayer::render( RenderContext* renderContext )
{
	if(!isVisible()) return;

	RasterLayer::render(renderContext);

	renderContext->painter()->save();

	QPen pen = renderContext->painter()->pen();
	pen.setColor(Qt::red);
	pen.setWidth(1);

	renderContext->painter()->setPen(pen);

	for (size_t i = 0; i < _drawedPolygons.size(); ++i)
	{
		QPolygon polygon = renderContext->mapToPixel().mapToScreen(_drawedPolygons[i]);
		renderContext->painter()->drawPolygon(polygon);
	}	

	renderContext->painter()->restore();
}
